<?php
/**
 *      [迷你云] (C)2009-2012 南京恒为网络科技.
 *   软件仅供研究与学习使用，如需商用，请访问www.miniyun.cn获得授权
 * 
 */
?>
<?php
@session_start();
$initialized = false;$dbConfig = array( 'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/init.db',
);
$gps_enable=false;
$extent=get_loaded_extensions();
$exif_extent=false;
$mbstring_extent=false;
if(is_array($extent)){
    foreach ($extent as $key=>$val){
        if($val=='mbstring'){
            $mbstring_extent=true;
        }
        if($val=='exif'){
            $exif_extent=true;
        }
    }
}
if($mbstring_extent && $exif_extent){
    $gps_enable=true;
}
$mysql_ini  = dirname(__FILE__).'/../../../mysql/my.ini';
if (file_exists($mysql_ini))
{
    $ini = @parse_ini_file($mysql_ini, true, INI_SCANNER_RAW);
    if ($ini && array_key_exists("mysqld", $ini))
    {
        $mysqld = $ini["mysqld"];
        if (array_key_exists("port", $mysqld))
        {
            define('DB_PORT', $mysqld["port"]);
        }
    }
}

require_once dirname(__FILE__).'/config.php';
$path        = dirname(__FILE__)."/../../upload/";$configPath  = dirname(__FILE__).'/miniyun-config.php';
$tablePrefix = "miniyun_";
$key         = "key";
$eversion    = EVERSION;       if(file_exists($configPath)){
    require_once $configPath;
    $initialized = true;
    $tablePrefix = DB_PREFIX."_";
    $key         = KEY;
    $path        = BASE;
    $dbConfig = array(
            'connectionString' => 'mysql:host='.DB_HOST.';dbname='.DB_NAME.';port='.DB_PORT.";",
            'emulatePrepare' => true,
            'username' => DB_USER,
            'password' => DB_PASSWORD,
            'charset' => DB_CHARSET,
    );
}else{
        unset($_SESSION['user']);
    unset($_SESSION['siteOptions']);     unset($_SESSION['appOptions']); }

$status_path = dirname(__FILE__).'/system-config.php';
if (file_exists($status_path)) {
    require_once($status_path);
}

if(array_key_exists("siteOptions", $_SESSION)){
    $siteOptions = $_SESSION["siteOptions"];
    if ($siteOptions["sitePort"] != $_SERVER['SERVER_PORT']){
        unset($_SESSION['user']);
        unset($_SESSION['siteOptions']);         unset($_SESSION['appOptions']);         
        if (isset($_COOKIE['page_oldurl_cook'])) {
            setcookie("page_oldurl_cook", "");
        }
    }
}

if(array_key_exists("siteOptions", $_SESSION)==false){
    $siteOptions = array();
    $siteOptions["protocol"]        = array_key_exists("HTTPS", $_SERVER) ? "https" : "http";    $siteOptions["siteName"]        = "迷你云";    $siteOptions["siteUrl"]         = $siteOptions["protocol"] . "://" . $_SERVER['HTTP_HOST'];    $siteOptions["baseUrl"]         = $siteOptions["siteUrl"].substr($_SERVER['SCRIPT_NAME'],0, strlen($_SERVER['SCRIPT_NAME'])-10);            $siteOptions["siteLogo"]        = "/statics/images/miniyun-logo.png";    $siteOptions["siteTitle"]       = "爱生活,爱分享";    $siteOptions["siteLogoSmall"]   = "/statics/images/miniyun-logo-small.png";    $siteOptions["defaultSpace"]    = defined('DEFAULT_USER_SPACE')? DEFAULT_USER_SPACE:100;    $siteOptions["company"]         = "www.miniyun.cn";
    $siteOptions["enabledReigster"] = true;    $siteOptions["enableMail"]      = "1";    $siteOptions["registerUrl"]     = "";
    $siteOptions["getpwUrl"]        = "";
    $siteOptions["mid"]             = "";
    $siteOptions["sitePort"]        = $_SERVER['SERVER_PORT'];

    $_SESSION["siteOptions"]        = $siteOptions;
}


if($initialized){
    if(array_key_exists("appOptions", $_SESSION)==false){
        
        function getAppOptions($tablePrefix){
            $link = mysql_connect(DB_HOST.":".DB_PORT, DB_USER, DB_PASSWORD)
            or die('Could not connect: ' . mysql_error());
            mysql_select_db(DB_NAME) or die('Could not select database');
            mysql_set_charset(DB_CHARSET,$link);
            $retVal = array();
            $query = "SELECT * FROM ".$tablePrefix."options";
            $result = mysql_query($query) or die('Query failed: ' . mysql_error());
            while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
                $retVal[$line["option_name"]]=$line["option_value"];
            }
            mysql_free_result($result);
            mysql_close($link);
            return $retVal;
        }
        $appOptions = getAppOptions($tablePrefix);
        if(array_key_exists("site_name", $appOptions)){
            $siteOptions["siteName"] = $appOptions["site_name"];
        }
        if(array_key_exists("site_url", $appOptions)){
                    }
        if(array_key_exists("site_title", $appOptions)){
            $siteOptions["siteTitle"] = $appOptions["site_title"];
        }
        if(array_key_exists("site_logo_url", $appOptions)){
            $siteOptions["siteLogo"] = $appOptions["site_logo_url"];
        }
        if(array_key_exists("site_logo_small_url", $appOptions)){
            $siteOptions["siteLogoSmall"] = $appOptions["site_logo_small_url"];
        }
        if(array_key_exists("site_default_space", $appOptions)){
            $siteOptions["defaultSpace"] = $appOptions["site_default_space"];
        }
        if(array_key_exists("site_company", $appOptions)){
            $siteOptions["company"] = $appOptions["site_company"];
        }
        if(array_key_exists("user_register_enabled", $appOptions)){
            $siteOptions["enabledReigster"] = $appOptions["user_register_enabled"]=="1"?true:false;
        }
        if(array_key_exists("user_create_url", $appOptions) && !empty($appOptions["user_create_url"])){
            $siteOptions["registerUrl"] = $appOptions["user_create_url"];
        }else{
            $siteOptions["registerUrl"] = $siteOptions["baseUrl"]."/index.php?r=site/register";        }
        if(array_key_exists("user_getpwd_url", $appOptions) && !empty($appOptions["user_getpwd_url"])){
            $siteOptions["getpwUrl"] = $appOptions["user_getpwd_url"];
        }else{
            $siteOptions["getpwUrl"] = $siteOptions["baseUrl"]."/index.php?r=site/forgetpasswd";        }
        if(array_key_exists("mail_enabled_email", $appOptions)){
            $siteOptions["enableMail"] = $appOptions["mail_enabled_email"];
        }
        if(array_key_exists("mid", $appOptions)){
            $siteOptions["mid"] = $appOptions["mid"];
        }
        $_SESSION["appOptions"]= $appOptions;
        $_SESSION["siteOptions"]= $siteOptions;
    }
}
$siteOptions = $_SESSION["siteOptions"];
header('Content-Type: text/html; charset=UTF-8');
define( "WB_AKEY" , '4159367632' );
define( "WB_SKEY" , '0672a235b298779d60f2b5f455bc4b13' );
define( "WB_CALLBACK_URL" , '/index.php?r=adminControlPanel/index' );



$adminSiteMap = array(            "控制面板"=>array(
            '首页'=>'adminControlPanel/index',
            '在线用户'=>'adminControlPanel/online', 
            "我的{$siteOptions['siteName']}"=>'netdisk/index',
            '使用协议许可' => 'site/license '
),
        "文件管理"=>array(
            '文件'=>'adminFilePanel/index',
            '办公文档'=>'adminFilePanel/office&office=1',
            '图片管理'=>'adminFilePanel/image&image=1',
            '文件回收站'=>'adminFilePanel/trash&trash=1',
            '统计图表'=>'adminFilePanel/stat',
),
        "用户管理"=>array(
            '用户管理'=>'adminUserPanel/index',
            '新建用户'=>'adminUserPanel/create',
            '个人信息'=>'adminUserPanel/update',
            '统计图表'=>'adminUserPanel/stat', 
),
        "系统管理"=>array(
            '常用设置'=>'adminSettingPanel/index', 
            '邮件服务器设置'=>'adminSettingPanel/emailServer',
            '用户源设置'=>'adminSettingPanel/user',

),
        "App 管理"=>array(
            'APP 管理'   => 'adminApp/index',
            'APP 新建'     => 'adminApp/create', 
),
        "API 中心"=>array(
            'API PV统计'   => 'adminApi/pvStat',
            'API 性能'     => 'adminApi/perStat', 
            'API 错误日志' => 'adminApi/errorLog',
            'API 文档'     => 'http://www.miniyun.cn/index.php?r=development/index',
),
);



return array(
    'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
    'name'=>'Miniyun',
    'preload'=>array('log','initialize'),
    'import'=>array(
        'application.models.*',
        'application.components.*',
        'ext.eoauth.*',
        'ext.eoauth.lib.*',
        'application.models.options.*',
        'application.models.site.*',
        'application.models.control.*',
        'application.models.files.*',
        'application.models.install.*',
        'application.models.user.*', 
        'application.models.online.*',
		'application.models.api.*', 
        'application.models.account.*', 
        'application.models.app.*', 
        'application.utils.*',
        'application.common.*',
        'application.common.uservalid.*',
        'application.common.db.*',
        'application.common.list.*',
        'application.common.base.*',
        'application.common.api.*',
        'application.common.helpers.*',
		'application.common.browser.*',
        'application.extensions.HttpClient.*',

        'application.api.*',
		'application.api.common.*',
		'application.api.common.cache.*',
        'application.api.common.interface.*',
        'application.api.controller.*',
        'application.api.controller.account.*',
        'application.api.controller.adapter.*',
        'application.api.controller.device.*',
        'application.api.controller.file_shares.*',
        'application.api.controller.fileops.*',
        'application.api.controller.files.*',
        'application.api.controller.medias.*',
        'application.api.controller.oauth.*',
		'application.api.controller.revisions.*',
        'application.api.controller.security.*',
        'application.api.controller.thumbnails.*',
        'application.api.controller.version.*',
        'application.api.extentions.image.*',
        'application.api.extentions.image.drivers.*',
        'application.api.extentions.image.helpers.*',
        'application.api.filter.*',
        'application.api.log4php.*',
        'application.api.log4php.appenders.*',
        'application.api.log4php.configurators.*',
        'application.api.log4php.helpers.*',
        'application.api.log4php.layouts.*',
        'application.api.log4php.renderers.*',
        'application.api.model.*',
        'application.api.third.oauth.*',
        'application.api.third.oauth.body.*',
		'application.api.third.oauth.discovery.*',
        'application.api.third.oauth.session.*',
        'application.api.third.oauth.signature_method.*',
        'application.api.third.oauth.store.*',
        'application.api.third.oauth.mysql.*',

),
        'modules'=>array(),
        'components'=>array(
            'user'=>array(
                'allowAutoLogin'=>true,
),
            'session'=>array(
                    'timeout'=>1800,
),
            'db'=>$dbConfig,
            'errorHandler'=>array(
                'errorAction'=>'site/error',
),
            'log'=>array(
                'class'=>'CLogRouter',
                'routes'=>array(
array(
                                'class'=>'CFileLogRoute',
                                'levels'=>'error, warning',
),
),
),
            'image'=>array(
                'class' => 'application.extensions.image.CImageComponent',
                'driver' => 'GD',  ),
),

    'params'=>array(
        'adminEmail'       => 'webmaster@example.com',
        'tablePrefix'      => $tablePrefix,        'defaultAvatar'    => '/statics/images/defaultavatar.png',        'iconUserEnabled'  => '/statics/images/userenabled.png',        'iconUserDisabled' => '/statics/images/userdisabled.png',        'iconUserAdmin'    => '/statics/images/useradmin.png',        'iconUserNormal'   => '/statics/images/usernormal.png',        'iconFolder'       => "/statics/images/folder.png",        'iconFile'         => "/statics/images/file.png",         'iconWord'         => "/statics/images/word.png",        'iconExcel'         => "/statics/images/excel.png",        'iconPpt'         => "/statics/images/ppt.png",        'iconText'         => "/statics/images/text.png",        'iconVideo'         => "/statics/images/video.png",        'iconAudio'         => "/statics/images/audio.png",        'app'=>array(            'initialized'=>$initialized,            'version'=>"1.0.0",            'name'=>$siteOptions['siteName'],			'title'=>$siteOptions['siteTitle'],            'logo'=>$siteOptions['siteLogo'],            'logoSmall'=>$siteOptions['siteLogoSmall'],            'host'=>$siteOptions['baseUrl'],            'company'=>$siteOptions['company'],            'defaultSpace'=>$siteOptions['defaultSpace'],            'enabledReigster'=>$siteOptions['enabledReigster'],            'registerUrl'=>$siteOptions['registerUrl'],            'getpwUrl'=>$siteOptions['getpwUrl'],            'enableMail'=>$siteOptions['enableMail'],            'mid'=>$siteOptions['mid'],            'eversion'=>$eversion,                 'key'=>$key,            'path'=>$path,            'apiVersion'=>"1",             'uploadSize'=>ini_get("post_max_size")<1024? ini_get("post_max_size")*1024*1024:1024*1024*1024,
            'version'=>"1.0",
            'gpsEnable'=>$gps_enable
),
            'adminSiteMap'=>$adminSiteMap,                       'officeType'=>array(
            't0'=>'application/msword',
            't1'=>'application/msexcel',
            't2'=>'application/mspowerpoint',
            't3'=>'application/pdf',
            't4'=>'text/plain',
            't5'=>'application/rtf',
),
    'helpDocument'=>array(
            'target'=>'_black',                 'img'=>"<img title=\"获取帮助\" height=\"20px\" src=\"".$siteOptions['baseUrl']."/statics/images/help.png\">",                 'online'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=47&extra=page=1',       
            'manageFile'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=48&extra=page%3D1',                     'removeFile'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=51&extra=page%3D1',                     'deleteFile'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=52&extra=page%3D1',                     'revertFile'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=53&extra=page%3D1',                     'showFile'  =>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=56&extra=page%3D1',                     'fileStat'  =>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=50&extra=page%3D1',         
            'manageUser'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=57&extra=page%3D1',                 'createUser'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=58&extra=page%3D1',                 'updateUser'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=59&extra=page%3D1',                 'deleteUser'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=60&extra=page%3D1',                 'userStat'  =>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=61&extra=page%3D1',       
            'setting'    =>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=62&extra=page%3D1',                    'emailServer'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=63&extra=page%3D1',    
            'manageApp'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=64&extra=page%3D1',                 'createApp'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=65&extra=page%3D1',                 'updateApp'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=66&extra=page%3D1',                 'deleteApp'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=67&extra=page%3D1',     
            'pvStat'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=68&extra=page%3D1',                   'perStat'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=70&extra=page%3D1',                  'errorLog'=>'http://bbs.miniyun.cn/forum.php?mod=viewthread&tid=71&extra=page%3D1',     ),
    'fileAction'=>array(
            '创建目录',              '删除目录、文件',              '移动目录、文件,或者重命名',              '创建文件',              '修改文件',  ),
    'rootDir'=>array(
            'demo', ),
),
);